package me.dev.demo;

import com.jfinal.core.Controller;
import com.jfinal.validate.Validator;

/******************************************************************************
 * 北京易华录信息技术股份有限公司
 * ----------------------------------------------------------------------------
 * 模块名称:模块名称
 * 类 名 称:me.dev.demo.AddUserValidator
 * 版　　本:Version 1.0
 * <p/>
 * 作 成 日:12/23/2015   Version 1.0   作　成　者:Liuwx
 * 最终更新:12/23/2015   Version 1.0   最终更新者:Liuwx
 * ----------------------------------------------------------------------------
 * 更新履历:
 * 12/23/2015   Version.1.0   初版作成者:Liuwx
 ******************************************************************************/

public class AddUserValidator extends Validator {
    /**
     * Use validateXxx method to validate the parameters of this action.
     *
     * @param c
     */
    @Override
    protected void validate(Controller c) {
        validateRequiredString(0, "nameMsg", "请输入用户名");
        validateRequiredString(1, "passMsg", "请输入密码");
    }

    /**
     * Handle the validate error.
     * Example:<br>
     * controller.keepPara();<br>
     * controller.render("register.html");
     *
     * @param c
     */
    @Override
    protected void handleError(Controller c) {
        c.keepPara("name");
        String userName = c.getAttr("nameMsg");
        String password = c.getAttr("passMsg");
        if (userName != null) {
            c.renderText(userName);
        }else if (password != null) {
            c.renderText(password);
        }
    }
}
